<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
</head>

<body>
<form id="loginForm">
    <label for="username">账号:</label>
    <input type="text" id="username" name="username" required><br><br>
    <label for="password">密码:</label>
    <input type="password" id="password" name="password" required><br><br>
    <button type="button" onclick="login()">登录</button>
</form>
<div id="errorMessage" style="color: red;"></div>

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    function login() {
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;

        axios.post('http://localhost:8080/login', {
            username: username,
            password: password
        })
            .then(response => {
                if (response.data.status === 200) {
                    // 登录成功，跳转到学生列表页面
                    window.location.href = 'AxiosDemo.html';
                } else {
                    // 登录失败，显示错误信息
                    document.getElementById('errorMessage').innerHTML = response.data.message;
                }
            })
            .catch(error => {
                console.error('登录请求出错:', error);
                document.getElementById('errorMessage').innerHTML = '登录请求出错，请稍后重试';
            });
    }
</script>
</body>

</html>